<template>
  <div class="allBox">
    <div class="loginBox">
      <h1>登录</h1>
      <ul>
        <li>
          <div class="username">账号:<input type="text" v-model="username" :placeholder="请输入账号"></div>
        </li>
        <li>
          <div class="password">密码:<input type="password" v-model="password" :placeholder="请输入密码"></div>
        </li>
        <li>
          <el-button :plain="true" @click="login">登录</el-button>
          <el-button :plain="true" @click="Register">注册</el-button>
        </li>
      </ul>
    </div>

  </div>

</template>

<script>
import {login} from "../../Api/User.js";

export default {
  name: "login",
  data() {
    return {
      username: '',
      password: '',
    }
  },
  methods: {
    login(){
      const user = {
        username: this.username,
        password: this.password
      }
      login(user).then(res=> {
        console.log("后端完整响应对象：", res);
        console.log("后端返回的核心数据（res.data）：", res.data);
        if (res.code == "200") {
          this.$message({
            message: '登陆成功',
            type: 'success'
          });
          this.$router.push('/Admin')
        } else {
          console.log("后端返回业务错误：", res.msg);
          this.$message({
            message: '账号或密码错误',
            type: 'warning'
          });
        }
      }).catch(err=> {
        console.log("请求失败：", err);
      })
    },
    Register(){
      this.$router.push('/Register')
    }
  },
}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
ul{
  list-style: none;
  padding: 0;
  margin: 0;
}

.allBox{
  background-image: url(../../public/灰原哀.jpg);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-color: rgba(255,255,255,0.5);
  height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: #333;
  border-radius: 20px;
  overflow: hidden;
  margin: 0;
}
.loginBox{
  width: 400px;
  height: 500px;
  margin: 0 auto;
  text-align: center;
  border: 1px solid #ccc;
  padding: 20px;
  margin-top: 100px;
  border-radius: 5px;
  box-shadow: 0 0 10px #ccc;
  background: #fff;
  box-sizing: border-box;
  background-color: rgba(255,255,255,0.3);
  backdrop-filter: blur(5px);
}
h1{
  font-size: 70px;
  margin-top: 50px;
  color: #333;
  text-shadow: 0 0 5px #ccc;
  text-align: center;
  font-weight: bold;
  font-family: '楷体';
  font-style: normal;
  text-decoration: none;
  line-height: 1.5;
  cursor: default;

}
.username, .password{
  margin-bottom: 20px;
  width: 100%;
  font-size: 20px;
  color: #333;
  font-weight: bold;
  font-family: "楷体";
  font-style: normal;
  text-decoration: none;
  line-height: 1.5;
  cursor: default;
}
.username input, .password input{
  width: 80%;
  height: 40px;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 0 10px;
  box-sizing: border-box;
  background-color: rgba(255,255,255,0.5);
  box-shadow: 0 0 5px #ccc;
  outline: none;
  font-size: 16px;
  margin-top: 20px;
}
.username input:focus, .password input:focus{
  background-color: rgba(255,255,255,0.6);
  box-shadow: 0 0 5px #333;
  outline: none;
  transition: all 0.3s;
}
.username input::placeholder, .password input::placeholder{
  color: #333;
}
button{
  width: 80px;
  height: 40px;
  background-color: rgba(255,255,255,0.5);
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 5px #ccc;
  cursor: pointer;
  transition: all 0.3s;
  outline: none;
}
button:hover{
  background-color: rgba(255,255,255,0.6);
  box-shadow: 0 0 5px #333;
  transition: all 0.3s;
}
</style>